package com.claude.communication;


import org.json.JSONObject;

import com.android.volley.Request.Method;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

public class RequestNode {
	private JsonObjectRequest mJsonObjectRequest = null;
	private String mUrl = null;
	private Listener<JSONObject> mListener = null;
	private ErrorListener mErrorListener = null;
	private JSONObject mParams = null;
	private RequestListener mRequestListener = null;
	private int mTag;

	public RequestNode(String url, final RequestListener requestListener,
			final JSONObject params, int tag) {
		this.mTag = tag;
		this.mUrl = url;
		this.mParams = params;
		this.mRequestListener = requestListener; 
		this.mListener = new Listener<JSONObject>() {
			public void onResponse(JSONObject arg0) {
				mRequestListener.onSuccess(arg0, mTag);
			}
		};
		this.mErrorListener = new ErrorListener() {
			public void onErrorResponse(VolleyError arg0) {
				mRequestListener.onError(arg0, mTag);
			}
		};
		mJsonObjectRequest = new JsonObjectRequest(Method.POST, this.mUrl,
				mParams, mListener, mErrorListener);
	}

	public JsonObjectRequest getJsonObjectRequest() {
		return this.mJsonObjectRequest;
	}

	public interface RequestListener {
		abstract public void onSuccess(JSONObject jsonObject, int tag);

		abstract public void onError(VolleyError volleyError, int tag);
	}
}
